/*
 * LimInfCred.java
 *
 * Created on 9 de octubre de 2001, 12:15
 */

package InterfacesDiscretas;

/**
 *
 * @author  administrador
 * @version
 */
import javax.swing.*;
public class LimInfCred extends javax.swing.JDialog {
    
    private static double L;
    private InterfacesGenerales.Plataforma Padre2;
    private InterfacesDiscretas.PlataformaDiscreta Padre;
    
    private int n_alternativas;
    
    private double[] q;
    private double[] p;
    private double[] v;
    
    public LimInfCred(InterfacesDiscretas.PlataformaDiscreta parent,InterfacesGenerales.Plataforma parent2,boolean modal,double[]q,double[]p,double[]v) {
        super(parent2, modal);
        initComponents();
        pack();
        jButton2.grabFocus();
        Padre = parent;
        Padre2=parent2;
        this.q=q;
        this.p=p;
        this.v=v;
        java.awt.Dimension nombre=java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(nombre.width/4,nombre.height/4);
        //setBounds(nombre.width/4,nombre.height/4,nombre.width/3+70,nombre.height/3-20);
        n_alternativas=DatosEntrada.DatosDiscretos.getNumeroAlt();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the FormEditor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        getContentPane().setLayout(new java.awt.GridBagLayout());

        setTitle("Electre III");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        jPanel1.setLayout(new java.awt.GridBagLayout());

        jPanel1.setBorder(new javax.swing.border.EtchedBorder());
        jPanel1.setMinimumSize(new java.awt.Dimension(250, 36));
        jPanel1.setPreferredSize(new java.awt.Dimension(250, 45));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("   Ingrese un valor entre [0-1], para el");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        jPanel1.add(jLabel1, gridBagConstraints);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("    L\u00edmite Inferior de Credibilidad");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 100.0;
        jPanel1.add(jLabel2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 100.0;
        gridBagConstraints.weighty = 40.0;
        getContentPane().add(jPanel1, gridBagConstraints);

        jPanel2.setBorder(new javax.swing.border.EtchedBorder());
        jPanel2.setMinimumSize(new java.awt.Dimension(194, 45));
        jPanel2.setPreferredSize(new java.awt.Dimension(224, 45));
        jLabel4.setForeground(new java.awt.Color(0, 0, 153));
        jLabel4.setText("L\u00edmite Inferior de credibilidad :");
        jPanel2.add(jLabel4);

        jTextField2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField2.setText("0.5");
        jTextField2.setPreferredSize(new java.awt.Dimension(40, 25));
        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        jPanel2.add(jTextField2);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 100.0;
        gridBagConstraints.weighty = 40.0;
        getContentPane().add(jPanel2, gridBagConstraints);

        jButton2.setText("Aceptar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel3.add(jButton2);

        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel3.add(jButton1);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 100.0;
        gridBagConstraints.weighty = 20.0;
        getContentPane().add(jPanel3, gridBagConstraints);

    }//GEN-END:initComponents
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        setVisible(false);
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed
    
  private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
      try{
          Double lic = new Double(jTextField2.getText());
          L=lic.doubleValue();
      } catch(NumberFormatException e){
          jTextField2.setText("");
          jTextField2.grabFocus();
      }
      if(L<0){
          JOptionPane.showMessageDialog(null,"El valor a ingresar debe ser positivo","Error",JOptionPane.WARNING_MESSAGE);
      }else{}
      if(L>1){
          JOptionPane.showMessageDialog(null,"El limite inferior de credibilidad debe estar entre valores de 0 a 1","Advertencia",JOptionPane.WARNING_MESSAGE);
      }
  }//GEN-LAST:event_jTextField2ActionPerformed
  
  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
      boolean cerrar=false;
      try{
          
          L=Double.parseDouble(jTextField2.getText());
          cerrar=true;
      } catch(NumberFormatException e){
          jTextField2.setText("");
          jTextField2.grabFocus();
          cerrar=false;
      }
      if(L<0){
          JOptionPane.showMessageDialog(null,"El valor a ingresar debe ser positivo","Error",JOptionPane.WARNING_MESSAGE);
      }else if(L>1){
          JOptionPane.showMessageDialog(null,"El limite inferior de credibilidad debe estar entre valores de 0 a 1","Advertencia",JOptionPane.WARNING_MESSAGE);
      }
      if(cerrar==true){
          
          String[] result=new String[n_alternativas];
          MetodosDiscretos.Electre3 run=new MetodosDiscretos.Electre3(q,p,v,L);
          int [][] matrizT=run.getMatrizT();
          
          result=run.getResultadoFinal();
          
          //Prueba de la sensibilidad de los pesos
          Sensibilidad.Spesos S=new Sensibilidad.Spesos(q, p, v, L, true);
          
          ResultadosDiscretos.Resultados objeto2= new ResultadosDiscretos.Resultados(" ELECTRE III "," Electre III ",result,q,p,v,matrizT,L,S.intervalos());
          Padre.getJDesktopPane2().add(objeto2);
          Padre.getJTabbedPane1().setSelectedIndex(3);
          setVisible(false);
          dispose();
          
      }
  }//GEN-LAST:event_jButton2ActionPerformed
  
  /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        setVisible(false);
        dispose();
    }//GEN-LAST:event_exitForm

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel4;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
}